package com.jt.redis;

import redis.clients.jedis.Jedis;

/**
 * @author tang
 * @data 2021/10/9
 * @apiNode
 *
 * 分布式id生成
 */
public class IdGeneratorDemo01 {

    public  static  Long getId(){
        Jedis jedis = new Jedis("192.168.126.129", 6379);
        //incr方法用于对指定key的值进行递增,假如key不存在则创建
        Long id = jedis.incr("id");
        jedis.close();
        return id;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            //new Thread(){
            //    @Override
            //    public void run() {
            //        System.out.println("id = " + IdGeneratorDemo01.getId());
            //    }
            //}   .start();
            new Thread(() -> System.out.println("id = " + getId())).start();
        }
    }
}
